require(['zTreeCheckbox','highcharts','canGrid', 'homePageTools'], function () {
	//==========================================变量
	//TODO
	var dateType = '02',															//日期，默认昨天
		lineId="",																		//线路id
		lineName="",																	//线路名称
		setting="",																	//线路树设置
		dateAr = [],																//日期数组
		dateString="",																	//日期字符串
		$avgEnergyIndex = $("#avgEnergyIndex"),										//百公里能耗
		$energyExceptionCount = $("#energyExceptionCount"),							//异常能耗统计
		$energyExceptionCars = $("#energyExceptionCars"),							//异常能耗车台数
		$energyConclusion = $("#energyConclusion"),									//能耗结论
		$avgEnergySpan = $("#avgEnergySpan"),										//百公里能耗环比
		//指标变量
		oilIndex=0,																	//油耗指标
		oilPerVal=0,																//油耗环比
		gasIndex=0,																	//气耗指标
		gasPerVal=0,																//气耗环比
		elecIndex=0,																//电耗指标
		elecPerVal=0,																//电耗环比
		oilCost=0,																	//油耗成本
		oilCostPer=0,																//油耗成本环比
		elecCost=0,																	//电耗成本
		elecCostPer=0,																//电耗成本环比
		gasCost=0,																	//气耗成本
		gasCostPer=0;																//气耗成本环比
	//===================函数
	//TODO
	/**
	 * 初始化页面各个元素
	 */
	function initElements(){
		//初始化线路树配置
		setting = {
		        view: {
		            showIcon: true,
		            selectedMulti: false
		        },
		        data: {
		            key: {
		                name: "name"
		            },
		            simpleData: {
		                enable: true,
		                idKey: "id",
		                pIdKey: "parentId",
		                rootPId: 0
		            }
		        },
		        callback: {
		            beforeClick: function (treeId, treeNode) {
		                return treeNode.type == 'LINE';
		            },
		            onClick: function (event, treeId, treeNode) {
		                if (treeNode.id == lineId) {
		                    return;
		                }
		                var loadMask = $.createMask();
		                setLine(treeNode);
		                //加载各项
		                initPageData();
		                setTimeout(function () {
		                    loadMask.remove();
		                }, 50);
		            }
		        }
		 };
		//初始化能耗异常排名表
		$("#energyExceptionTab").canGrid({
			url: "/homeEnergy/getEnergyExceptionRanking.htm",
			height:200,
	        colModel: [
	            {name: "licPltNo", label: '车牌号', width: '23%'},
	            {name: "carType", label: '车辆类型', width: '23%'},
	            {name: "rngMile", label: '行驶里程(km)', width: '23%'},
	            {name: "rngOprtDura", label: '运行时长(小时)', width: '30%'}
	        ]
	    });
		
		//能耗成本报表
		initEnergyCostTab($("#energyCostTab"), 'L');
		initEnergyCostTab($("#elecEnergyCostTab"), 'KW');
		initEnergyCostTab($("#gasEnergyCostTab"), 'L');
		
		//能耗相关不良行为
		$("#energyRiseDriver").canGrid({
			url: "/homeEnergy/getEnerMultiInfo.htm",
	        colModel: [
	            {name: "energyEffectItem", label: '与能耗相关不良行为', width: '33%'},
	            {name: "occurCount", label: '实际区间', width: '33%'},
	            {name: "referenceCount", label: '参考区间', width: '33%'}
	        ]
	    });
		//能耗相关车辆故障
		$("#energyRiseCar").canGrid({
			url: "/homeEnergy/getEnerMultiInfo.htm",
	        colModel: [
	            {name: "energyEffectItem", label: '与能耗相关车辆故障', width: '45%'},
	            {name: "occurCount", label: '次数', width: '45%'}
	        ]
	    });
		
		
		//初始化能耗排名报表
		initCarEnergyRanking($("#carOilRanking"), 'L/100KM');
		initCarEnergyRanking($("#carElecRanking"), 'KW/100KM');
		initCarEnergyRanking($("#carGasRanking"), 'L/100KM');
		//初始化驾驶员能耗排名
		initDriverEnergyRanking($("#driverOilRanking"), 'L/100KM');
		initDriverEnergyRanking($("#driverElecRanking"), 'KW/100KM');
		initDriverEnergyRanking($("#driverGasRanking"), 'L/100KM');
	}
	
	function initEnergyCostTab(obj, unit){
		obj.canGrid({
			url: "/homeEnergy/getEnergyCostRanking.htm",
			height:200,
	        colModel: [
	            {name: "reportDate", label: '日期', width: '15%'},
	            {name: "lineName", label: '线路', width: '13%'},
	            {name: "carCounts", label: '台数', width: '10%'},
	            {name: "energyConsum", label: '营运能耗('+unit+')', width: '12%'},
	            {name: "price", label: '单价(元)', width: '10%'},
	            {name: "lineAvgCost", label: '线路能耗费用<br>(元)', width: '16%'},
	            {name: "avgSoloCost", label: '单车平均能耗费用<br>(元/车)'}
	        ]
	    });
	}
	
	/**
     * 获取日期类型对应日期数据
     */
    function getFullDate(){
    	//TODO
    	$.ajaxExt({
    		async : false,
    		url:"/homeTransit/getFullDate.htm",
    		data:{
    			"dateType":dateType,
    			"yesterday":((new Date()).dateAdd('d',-1)).format()
//    			"yesterday":'2016-01-25'
    		}
    	}).done(function(data){
    		if(data && data.length > 0){
    			for(var i =0;i<data.length;i++){
    				dateAr.push(data[i].trendDate);
    			}
    			if(dateType=='02'){
    				//TODO
    	    		dateString = ((new Date()).dateAdd('d',-1)).format();
//    	    		dateString = '2016-01-25';
    	    	}else if(dateType == '03'){
    				dateString = data[0].trendDate+"-"+data[data.length-1].trendDate;
    			}else if(dateType == '04' || dateType == '05'){
    				dateString = data[0].trendDate.substring(0, 7)+"月";
    			}else if(dateType == '07' || dateType == '06'){
    				dateString = data[0].trendDate.substring(0, 4)+"年";
    			}
    		}
    	});
    }
	
	/**
	 * 初始车辆化能耗排名
	 * @param obj	列表元素
	 */
	function initCarEnergyRanking(obj, unit){
		obj.canGrid({
			url: "/homeEnergy/getEnergyCarsRanking.htm",
			height:250,
	        colModel: [
	            {name: "rankSn", label: '排名', align:'center',width: '15%'},
	            {name: "lineName", label: '线路', align:'center',width: '22%'},
	            {name: "licPltNo", label: '车牌号', align:'center',width: '22%'},
	            {name: "energyPerMile", align:'center',label: '百公里能耗('+unit+')'}
	        ]
	    });
	}
	
	/**
	 * 初始司机化能耗排名
	 * @param obj	列表元素
	 */
	function initDriverEnergyRanking(obj, unit){
		obj.canGrid({
			url: "/homeEnergy/getEnergyStatusRanking.htm",
			height:250,
	        colModel: [
	            {name: "rankSn", label: '排名', align:'center',width: '10%'},
	            {name: "lineName", label: '线路', align:'center',width: '17%'},
	            {name: "licPltNo", label: '车牌号', align:'center',width: '17%'},
	            {name: "drvName", label: '驾驶员', align:'center',width: '17%'},
	            {name: "energyPerMile", align:'center',label: '百公里能耗('+unit+')'}
	        ]
	    });
	}
	
	/**
     * 设置当前线路名称及ID
     * @param item ztree节点
     */
    function setLine(item) {
        lineId = item.id;
        $("#showlineName").html("当前线路 : " + item.name);
        lineName = item.name;
    }
    
    /**
     * 生成线路树
     */
	function initLineTree(){
		$.ajaxExt({
			async : false,
	        url: "/baseOrgan/getLeftOrg4Line.htm"
	    }).done(function(result){
	    	if ($.isArray(result)) {
                $.each(result, function (index, item) {
                    if (item.type == 'LINE') {
                        setLine(item);
                        return false;
                    }
                });
                $("#lineTree").createTree(setting, result, {search: $('#lineSelected')}).expandAll(true);
            }
	    });
	}
	
	/**
	 * 载入能耗指标内容
	 */
	function loadEnergyIndex(){
		$.ajaxExt({
			url:"/homeEnergy/getEnergyIndex.htm",
			data:{"dateType":dateType, "lineId":lineId, "clazzName":"EnergyIndexVo","funcType":"energyIndex"}
		}).done(function(data){
			var enerExcptVal=0, enerCarsVal=0;
			$energyExceptionCount.html("0");
			$energyExceptionCars.html("0");
			$energyConclusion.empty();
			if(data && data.length > 0){
				$energyConclusion.append("本月"+lineName+"<br>");
				//三种能耗指标
				oilIndex = data[0].oilConsum ? data[0].oilConsum : 0;
				oilPerVal = data[0].oilMomPer ? data[0].oilMomPer : 0;
				gasIndex = data[0].gasConsum ? data[0].gasConsum : 0;
				gasPerVal = data[0].gasMomPer ? data[0].gasMomPer : 0;
				elecIndex = data[0].elecConsum ? data[0].elecConsum : 0;
				elecPerVal = data[0].elecMomPer ? data[0].elecMomPer : 0;
				$avgEnergyIndex.html(oilIndex);
				fillIndex($avgEnergySpan, oilPerVal);
				//能耗结论
				$energyConclusion.empty();
				fillEnergyConclude(oilIndex, "L", oilPerVal, (data[0].oilYoyPer ? data[0].oilYoyPer : 0), "油");
				fillEnergyConclude(gasIndex, "L", gasPerVal, (data[0].gasYoyPer ? data[0].gasYoyPer : 0), "气");
				fillEnergyConclude(elecIndex, "KW", elecPerVal, (data[0].elecMomPerm ? data[0].elecMomPerm : 0), "电");
				//三种能耗成本
				oilCost = data[0].oilCostVal ? data[0].oilCostVal : 0;
				oilCostPer = data[0].oilCostPer ? data[0].oilCostPer : 0;
				elecCost = data[0].elecCostVal ? data[0].elecCostVal : 0;
				elecCostPer = data[0].elecCostPer ? data[0].elecCostPer : 0;
				gasCost = data[0].gasCostVal ? data[0].gasCostVal : 0;
				gasCostPer = data[0].gasCostPer ? data[0].gasCostPer : 0;
				$("#avgCostPerHour").html(oilCost);
				fillIndex($("#avgCostPerHourSpan"), oilCostPer);
				//能耗里程和时长
				var energyExcptVal = data[0].enerExcptVal ? data[0].enerExcptVal : 0;
				if(!isNaN(parseFloat(energyExcptVal))){
					enerExcptVal = parseFloat(energyExcptVal);
				}
				$("#energyExceptNum").html(enerExcptVal);//var 
				fillIndex($("#energyExceptNumSpan"), (data[0].enerExcptPer ? data[0].enerExcptPer : 0));
				
				var energyCarsVal = data[0].enerCarsVal ? data[0].enerCarsVal : 0;
				if(!isNaN(parseFloat(energyCarsVal))){
					enerCarsVal = parseFloat(energyCarsVal);
				}
				$("#energyExceptCarNum").html(enerCarsVal);
				fillIndex($("#energyExceptCarNumSpan"), (data[0].enerCarsPer ? data[0].enerCarsPer : 0));
				$energyExceptionCount.html(enerExcptVal);
				$energyExceptionCars.html(enerCarsVal);
				$energyConclusion.append("能耗水平有所变化，请考虑采取相应措施。<br>");
			}else{
				oilIndex = 0;
				oilPerVal = 0;
				$avgEnergyIndex.html("0");
				fillIndex($avgEnergySpan, 0);
				gasIndex = 0;
				gasPerVal = 0;
				elecIndex = 0;
				elecPerVal = 0;
				oilCost = 0;
				oilCostPer = 0;
				elecCost = 0;
				elecCostPer = 0;
				gasCost = 0;
				gasCostPer = 0;
				$("#avgCostPerHour").html("0");
				fillIndex($("#avgCostPerHourSpan"), 0);
				$("#energyExceptNum").html("0");
				fillIndex($("#energyExceptNumSpan"), 0);
				$("#energyExceptCarNum").html("0");
				fillIndex($("#energyExceptCarNumSpan"), 0);
				$energyExceptionCount.html(0);
				$energyExceptionCars.html(0);
			}
		});
	}
	
	/**
	 * 填充指标
	 */
	function fillIndex(obj, val){
		obj.removeClass();
		if(isNaN(parseFloat(val)) || val == 0){
			val = "0.0";
		}
		obj.addClass("icon-arrow-up");
		obj.html(val+"%");
		if(val < 0){
			obj.addClass("icon-arrow-down");
		}else if(val == 0){
			obj.addClass("icon-arrow-unchanged");
		}
	}
	
	/**
	 * 填充能耗结论
	 * @param energyVal 能耗值
	 * @param unit 单位
	 * @param energyPerMonth 环比
	 * @param energyPerYear 同比
	 * @param type 燃料类型
	 */
	function fillEnergyConclude(energyVal, unit, energyPerMonth, energyPerYear, type){
		
		if(isNaN(parseFloat(energyVal))){
			energyVal = "0";
		}
		if(isNaN(parseFloat(energyPerMonth))){
			energyPerMonth = "0";
		}
		if(isNaN(parseFloat(energyPerYear))){
			energyPerYear = "0";
		}
		var html = "平均"+type+"耗为"+energyVal+unit+"，";
		if(energyPerYear>0){
			html += "同比<strong class='c-red'>上升"+energyPerYear+"%</strong>，";
		}else if(energyPerYear<0){
			html += "同比<strong class='c-green'>下降"+energyPerYear+"%</strong>，";
		}else{
			html += "同比<strong>"+energyPerYear+"%</strong>，";
		}
		if(energyPerMonth>0){
			html += "环比<strong class='c-red'>上升"+energyPerMonth+"%</strong>，<br>";
		}else if(energyPerMonth<0){
			html += "环比<strong class='c-green'>下降"+energyPerMonth+"%</strong>，<br>";
		}else{
			html += "环比<strong>"+energyPerMonth+"%</strong>;<br>";
		}
		$energyConclusion.append(html);
	}
	
	/**
	 * 加载影响因素
	 */
	function loadInfluence(){
		$.ajaxExt({
			url:"/homeEnergy/getEnergyInfluence.htm",
			data:{"funcType":"energyInfluence", "dateType":dateType, "lineId":lineId, "clazzName":"EnergyInfluenceVo"}
		}).done(function(data){
			$("#bhvEnergyInfluence").empty();
			$("#drvEnergyInfluence").empty();
			if(data && data.length>0){
				var html = "";
				for(var i=0; i<data.length; i++){
					html += '<li>'+data[i].influenceFactors+'</li>';
					if(i==2){
						$("#drvEnergyInfluence").html(html);
						html = '';
					}
				}
				$("#bhvEnergyInfluence").html(html);
			}
		});
	}
	
	/**
	 * 生成趋势图(油，电，气，能耗异常分别调用) 030401 030402 030403 030801
	 * @param obj 图形元素
	 * @param type 图形类型
	 * @param idxType 业务类型
	 * @param title 标题
	 * @param unit 单位
	 * @param color 颜色
	 * @param name 能耗类别名称
	 */
	function initTendencyChart(obj, type, idxType,  title, unit, color, name){
		obj.html("");
		$.ajaxExt({
			url:"/homeEnergy/getEnergyTendencyChart.htm",
			data:{"funcType":"energyTendencyChart", "dateType":dateType, "lineId":lineId, "idxType":idxType, "clazzName":"EnergyTrendencyVo"}
		}).done(function(data){
			var category = [];
				var series = [{name:"百公里"+title+"耗", data:[]}],
				mainTitle = '百公里'+title+'耗趋势',
				subTitle = '线路：'+lineName+' 时间：'+dateString;
			//数据格式
			formatEnergyTendencyData(data, dateType, category, series, dateAr);
			//趋势图
			createEnergyTendencyChart(obj, type, color, mainTitle, subTitle, category, unit, series, dateType, idxType, data, lineName, dateString);
		});
	}
	
	/**
	 * 查询能耗相关报表信息
	 */
	function loadEnergyRankingTab(){
		$("#carOilRanking").canGrid('reload', {params:{"funcType":"energyCarsRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030501", "clazzName":"EnergyRankingVo"}});
		$("#carElecRanking").canGrid('reload', {params:{"funcType":"energyCarsRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030601", "clazzName":"EnergyRankingVo"}});
		$("#carGasRanking").canGrid('reload', {params:{"funcType":"energyCarsRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030701", "clazzName":"EnergyRankingVo"}});
		$("#driverOilRanking").canGrid('reload', {params:{"funcType":"energyStatusRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030502", "clazzName":"EnergyRankingVo"}});
		$("#driverElecRanking").canGrid('reload', {params:{"funcType":"energyStatusRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030602", "clazzName":"EnergyRankingVo"}});
		$("#driverGasRanking").canGrid('reload', {params:{"funcType":"energyStatusRanking" , "dateType":dateType,"lineId":lineId, "idxType":"030702", "clazzName":"EnergyRankingVo"}});
		$("#energyExceptionTab").canGrid('reload', {params:{"funcType":"energyExceptionRanking" , "dateType":dateType,"lineId":lineId, "clazzName":"EnergyExceptionRanking"}});
		$("#energyRiseDriver").canGrid('reload', {params:{"funcType":"enerMultiInfo" , "dateType":dateType,"lineId":lineId, "idxType":'031302', "clazzName":"EnergyMultiEffects"}});
		$("#energyRiseCar").canGrid('reload', {params:{"funcType":"enerMultiInfo" , "dateType":dateType,"lineId":lineId, "idxType":'031303', "clazzName":"EnergyMultiEffects"}});
	}
	
	/**
	 * 初始化成本分析图表
	 */
	function initEnergyCostTendencyChart(obj, idxType){
		$.ajaxExt({
			url:"/homeEnergy/getEnergyCostTendency.htm",
			data:{"funcType":"energyCostTendency", "dateType":dateType, "lineId":lineId, "clazzName":"EnergyCostTendencyVo", "idxType":idxType}
		}).done(function(data){
			var category = [], 
				series = [];
			var mainTitle = '',
				subTitle = '线路：'+lineName+' 时间：'+dateString;
			//格式化数据
			formatSafetyTendencyData(data, dateType, category, series, dateAr);
			//生成图
			var colors = ['#FF0000', '#00FF00', '#0000FF'];
			createMultiTendencyChart(obj, mainTitle, subTitle, category, colors, "元/车", series, dateType);
		});
	}
	
	/**
	 * 加载成本分析列表
	 */
	function initEnergyCostRanking(){
		$("#energyCostTab").canGrid('reload', {params:{"funcType":"energyCostRanking" , "dateType":dateType,"lineId":lineId, "clazzName":"EnergyCostRanking","idxType":"031201"}});
		$("#elecEnergyCostTab").canGrid('reload', {params:{"funcType":"energyCostRanking" , "dateType":dateType,"lineId":lineId, "clazzName":"EnergyCostRanking","idxType":"031202"}});
		$("#gasEnergyCostTab").canGrid('reload', {params:{"funcType":"energyCostRanking" , "dateType":dateType,"lineId":lineId, "clazzName":"EnergyCostRanking","idxType":"031203"}});
	}
	
	/**
	 * 加载能耗特征模型图
	 */
	function initEnergyStatusPieChart(){
		var dataAr = [];
		$.ajaxExt({
			url:"/homeEnergy/getEnergyStatusPieChart.htm",
			data:{"funcType":"energyStatusPieChart", "dateType":dateType, "lineId":lineId,"clazzName":"EnergyPropertyItemVo"}
		}).done(function(data){
			$("#energyStatusPieChart").empty();
			if(data && data.length>0){
				for(var i = 0; i < data.length; i++){
					dataAr.push([data[i].propertyItem, parseInt(data[i].propertyVal)||0]);
				}
				
				Highcharts.setOptions({  
					colors: ['#7cb5ec', '#434348', '#90ed7d', '#f7a35c', '#8085e9', 
					         '#f15c80', '#e4d354', '#8085e8', '#8d4653', '#91e8e1']
				}); 
				
				$("#energyStatusPieChart").highcharts({ 
					chart: { plotBackgroundColor: null, 
						plotBorderWidth: null,
						plotShadow: false }, 
						credits: {
							enabled: false
						},
						title: { text: '能耗特征模型分析' }, 
						tooltip: { formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +'%';
						}}, 
						plotOptions: { 
							pie: { allowPointSelect: true, 
								cursor: 'pointer', 
								dataLabels: { enabled: true, 
									color: '#000000', 
									connectorColor: '#000000', 
									format: '<b>{point.name}</b>: {point.y} %' 
								} 
							} 
						}, 
						series: [{ type: 'pie', 
							name: '能耗特征模型分析', 
							data: dataAr
						}]
				});
			}
		});
	}
	
	/**
	 * 能耗多重信息分析
	 */
	function initEnerMultiInfo(obj, idxType, title){
		$.ajaxExt({
			url:"/homeEnergy/getEnerMultiInfo.htm",
			data:{"funcType":"enerMultiInfo", "dateType":dateType, "lineId":lineId,"idxType":idxType, "clazzName":"EnergyMultiEffects"}
		}).done(function(data){
			obj.empty();
			if(data && data.length >0 ){
				var html = title;
				for(var i=0;i<data.length;i++){
					html += "<br>"+data[i].energyEffectItem+",控制在"+data[i].occurCount+"之间";
				}
				obj.html(html);
			}
		});
	}
	
	/**
	 * 逐步加载页面各项
	 */
	function initPageData(){
		persistCurrentCondition(lineId, lineName, dateType);
		
		$("#changeOilIndex").addActiveClass();
		loadEnergyIndex();
		loadInfluence();
		//加载能耗趋势
		initTendencyChart($("#oilTendencyChart"), 'areaspline', '030401', '油', 'L/100km','#FF5151', '线路平均百公里能耗');
		initTendencyChart($("#elecTendencyChart"), 'areaspline', '030402', '电', 'KW/100km','#79FF79', '线路平均百公里能耗');
		initTendencyChart($("#gasTendencyChart"), 'areaspline', '030403', '气', 'L/100km','#FF9224', '线路平均百公里能耗');
		//加载能耗排名
		loadEnergyRankingTab();
		//加载能耗异常排名图
		initTendencyChart($("#energyExceptionChart"), 'column', '030801', '线路运行里程趋势', 'KM','#FF9224', '行驶里程');
		//加载成本分析图表
		initEnergyCostTendencyChart($("#energyCostChart"), '030901', '油');//油
		initEnergyCostTendencyChart($("#elecEnergyCostChart"), '030902', '电');//电
		initEnergyCostTendencyChart($("#gasEnergyCostChart"), '030903', '气');//气
		//加载成本分析列表
		initEnergyCostRanking();
		//加载能耗特征模型图
		$("#energyStatusPieChart").empty();
		initEnergyStatusPieChart();
		$("#enerAdviceBhv").empty();
		initEnerMultiInfo($("#enerAdviceBhv"),'031304','<strong class="c-red">调整驾驶行为：</strong>');
		$("#enerAdviceMainte").empty();
		initEnerMultiInfo($("#enerAdviceMainte"),'031305','<strong class="c-red">做好维修保养，避免出现：</strong>');
	}
	
	/**
	 * 变更百公里能耗
	 * @param type	能耗类型
	 */
	function changeEnergyIndex(type){
		if(type=='oil'){
			$avgEnergyIndex.html(oilIndex);
			fillIndex($avgEnergySpan,  oilPerVal);
		}else if(type=='elec'){
			$avgEnergyIndex.html(elecIndex);
			fillIndex($avgEnergySpan,  elecPerVal);
		}else if(type=='gas'){
			$avgEnergyIndex.html(gasIndex);
			fillIndex($avgEnergySpan,  gasPerVal);
		}
	}
	
	/**
	 * 变更隐藏/显示
	 * @param type 显示标记 (0:表示第一个元素隐藏，第二个元素显示,1:反之)
	 * @param obj1 设置显示/隐藏的第一个元素
	 * @param obj2 设置显示/隐藏的第二个元素
	 */
	function showHideToggle(type, obj1, obj2){
		if(type==0){
			obj1.hide();
			obj2.show();
		}else{
			obj2.hide();
			obj1.show();
		}
	}
	
	/**
	 * 切换成本趋势和成本列表显示隐藏
	 */
	function costShowHide(chart, tab){
		$("#energyCostChart").hide();
		$("#elecEnergyCostChart").hide();
		$("#gasEnergyCostChart").hide();
		$("#oilCostTabDiv").hide();
		$("#elecCostTabDiv").hide();
		$("#gasCostTabDiv").hide();
		chart.show();
		tab.show();
	}
	
	/**
	 * 更改能耗标题和能耗成本指标
	 */
	function changeIndexTitleAndCost(type, costVal, perVal, unit){
		console.info(unit);
		$("#energyIndexTitle").html('平均百公里'+type+'耗'+unit);
		$("#costIndexTitle").html('平均百公里'+type+'耗费用（元）');
		$("#avgCostPerHour").html(costVal+"<em>元</em>");
		fillIndex($("#avgCostPerHourSpan"), perVal);
	}
	
	/**
	 * 自动加载
	 */
	function autoLoadData(){
		var condition = getCurrentCondition();
		var _cookileLineId = "";
		if(condition[0]){
			_cookileLineId = condition[0];
		}
		if (condition[1]) {
			dateType = condition[1];
		}
		if (lineId) {
			var treeObj = $.fn.zTree.getZTreeObj("lineTree");
			var node = treeObj.getNodeByParam("id", _cookileLineId, null);
			if (node) {
				$("#dateDiv").find('a').removeClass("active");
				$("#dateDiv").find('a[val="' + dateType + '"]').addClass("active");
				lineId = _cookileLineId;
				lineName = node.name;
				$("#showlineName").html("当前线路 : " + lineName);
				treeObj.selectNode(node);
				getFullDate();
				initPageData();
			} else {
				//载入后默认加载昨天
				$("#dateDiv").find('a:first').click();
			}
		} else {
			//载入后默认加载昨天
			$("#dateDiv").find('a:first').click();
		}
	}
	
	function energySummery(id, energyType){
		var data = {};
		var fuelTypeCode = null;
			fuelTypeCode = [];
		if($("#changeOilIndex").attr("class") == 'active'){
			fuelTypeCode = ['1', '2'];
		}else if($("#changeElecIndex").attr("class") == 'active'){
			fuelTypeCode.push('3');
		}else if($("#changeGasIndex").attr("class") == 'active'){
			fuelTypeCode = ['4', '5'];
		}
		data.energyType = fuelTypeCode;
		if(energyType){
			data.energyType = energyType;
		}
		data.energyTimeType = '10';
		if(dateType == '06' || dateType == '07'){
			data.energyTimeType = '7';
		}
		data.lineId = lineId;
		data.dateType = dateType;
		$.openTab(id, 'searchEnergyDetail', [data]);
	}
	
	//========================事件绑定
	//TODO
	//日期按钮设置
	$("#dateDiv").find('a').click(function(){
		$("#dateDiv").find('a').removeClass("active");
		dateType = $(this).attr("val");
		dateAr = [];
		getFullDate();
		$(this).addClass("active");
		initPageData();
	});
	
	//点击显示能耗对应类型的指标
	$("#changeOilIndex").click(function(){
		$(this).addActiveClass();
		changeEnergyIndex('oil');
		changeIndexTitleAndCost('油', oilCost, oilCostPer, "（L）");
	});
	$("#changeGasIndex").click(function(){
		$(this).addActiveClass();
		changeEnergyIndex('gas');
		changeIndexTitleAndCost('气', gasCost, gasCostPer, "（KW）");
	});
	$("#changeElecIndex").click(function(){
		$(this).addActiveClass();
		changeEnergyIndex('elec');
		changeIndexTitleAndCost('电', elecCost, elecCostPer, "（L）");
	});
	
	//设置隐藏显示切换
	$("input[name='changeOilRanking']").click(function(){
		var sign = $("input[name='changeOilRanking']:checked").val();
		showHideToggle(sign, $("#driverOilRankingDiv"), $("#carOilRankingDiv"));
	});
	$("input[name='changeElecRanking']").click(function(){
		var sign = $("input[name='changeElecRanking']:checked").val();
		showHideToggle(sign, $("#driverElecRankingDiv"), $("#carElecRankingDiv"));
	});
	$("input[name='changeGasRanking']").click(function(){
		var sign = $("input[name='changeGasRanking']:checked").val();
		showHideToggle(sign, $("#driverGasRankingDiv"), $("#carGasRankingDiv"));
	});
	
	$("#changeOilCost").click(function(){
		$(this).addActiveClass();
		costShowHide($("#energyCostChart"), $("#oilCostTabDiv"));
	});
	$("#changeElecCost").click(function(){
		$(this).addActiveClass();
		costShowHide($("#elecEnergyCostChart"), $("#elecCostTabDiv"));
	});
	$("#changeGasCost").click(function(){
		$(this).addActiveClass();
		costShowHide($("#gasEnergyCostChart"), $("#gasCostTabDiv"));
	});
	
	//------------跳转部分
	//TODO
	$("#energyIndexMore, #costIndexMore, #energyMileMore, #energyDurationMore").click(function(){
		energySummery('d0c6f14c2d3047fb91ec4c6e6bd55590');
	});
	
	$("#oilRankingMore").click(function(){
		var sign = $("input[name='changeOilRanking']:checked").val();
		var id = getFuncId(sign);
		energySummery(id, ['1', '2']);
	});
	$("#elecRankingMore").click(function(){
		var sign = $("input[name='changeElecRanking']:checked").val();
		var id = getFuncId(sign);
		energySummery(id, ['3']);
	});
	$("#gasRankingMore").click(function(){
		var sign = $("input[name='changeGasRanking']:checked").val();
		var id = getFuncId(sign);
		energySummery(id, ['4', '5']);
	});
	
	function getFuncId(sign){
		var id = 'd280237883a94d72a90530e4ace3931d';
		if(sign == '1'){
			id = '22a8cf4a8bef40ca9231911bce49d01b';
		}
		return id;
	}
	
	$("#energyCostMore1, #energyCostMore2").click(function(){
		$.openTab("e5345e55f67c4146a6990562a350391a");
	});
	
	
	//初始化页面元素
	initElements();
	//初始化页面
	initLineTree();
	//加载
	autoLoadData();
	
});